package com.fooddiary.model;

import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fooddiary.model.entity.BaseEntity;


/**
 * 
 * @author Created by andrey.kuznetsov <br>
 * @author Last modified by $Author$ <br>
 * @author Last modified on $Date$ at revision $Revision$ <br>
 */
@Entity
@Table(name = "eating")
@AttributeOverrides({
	@AttributeOverride(name="id", column=@Column(name="id")),
	@AttributeOverride(name="enabled", column=@Column(name="enabled"))
})
public class Eating extends BaseEntity implements Serializable, Comparable<Eating>{

	private static final long serialVersionUID = 192168711426604684L;

	@Column(name = "time", unique = false, nullable = false, insertable = true, updatable = true)
	private String time;
	
	@Column(name = "food", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
	private String food;
	
	@Column(name = "overweight", unique = false, nullable = false, insertable = true, updatable = true)
	private Short overweight;
	
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "weight_id")
	private Weight weight;
	
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "eating_type_id")
	private EatingType eatingType;

	/**
	 * Returns time of eating <{@link String}>
	 * @return {@link String};
	 */
	public String getTime() {
		return time;
	}

	/**
	 * Sets time of eating <br>
	 * @param p_time - {@link String};
	 */
	public void setTime(String p_time) {
		time = p_time;
	}

	/** 
	 * Returns food description <br>
	 * @return {@link String};
	 */
	public String getFood() {
		return food;
	}

	/**
	 * Sets food description <br>
	 * @param p_food - {@link String};
	 */
	public void setFood(String p_food) {
		food = p_food;
	}

	/**
	 * Returns overweight flag <br>
	 * @return {@link Short};
	 */
	public Short getOverweight() {
		return overweight;
	}

	/**
	 * Sets overweight flag <br>
	 * @param p_overweight - {@link Short};
	 */
	public void setOverweight(Short p_overweight) {
		overweight = p_overweight;
	}

	/**
	 * Returns weight <br>
	 * @return {@link Weight};
	 */
	public Weight getWeight() {
		return weight;
	}

	/**
	 * Sets weight <br>
	 * @param p_weight - {@link Weight};
	 */
	public void setWeight(Weight p_weight) {
		weight = p_weight;
	}

	/**
	 * Returns eating type <br>
	 * @return {@link EatingType};
	 */
	public EatingType getEatingType() {
		return eatingType;
	}

	/**
	 * Sets eating type <br>
	 * @param p_eatingType - {@link EatingType};
	 */
	public void setEatingType(EatingType p_eatingType) {
		eatingType = p_eatingType;
	}

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Eating p_eating) {
		if(getEatingType().getEatingOrder() > p_eating.getEatingType().getEatingOrder()){
			return 1;
		}else if(getEatingType().getEatingOrder() < p_eating.getEatingType().getEatingOrder()){
			return -1;
		}else{
			return 0;
		}
	}
	
	
}
